// middleware/error-handler.js
module.exports = async (ctx, next) => {
    try {
      await next();
    } catch (err) {
      ctx.status = err.status || 500;
      ctx.body = {
        message: err.message,
        error: err.errors,
      };
    }
  };